package com.baiyue.admin.common;

import javax.servlet.http.HttpServletRequest;

import com.baiyue.admin.entity.AdminInfo;
import com.baiyue.admin.entity.Operation;
import com.baiyue.admin.entity.Role;

/**
 * 权限认证.
 * @date  2014年3月18日
 */
public final class PermissionUtils {
	public static MessageResult checkPermission(HttpServletRequest request,String operation,String password) {
		//暂时返回true
		return new MessageResult(true,"该管理员有权限");
		
		/*AdminInfo adminInfo = (AdminInfo) request.getSession().getAttribute("adminInfo");
		if(adminInfo == null){
			MessageResult result  = new MessageResult();
			result.setSuccess(false);
			result.setMessage("session无效");
			return result;
		}
		if(operation == null){
			MessageResult result  = new MessageResult();
			result.setSuccess(false);
			result.setMessage("操作无权限");
			return result;
		}
		String role = adminInfo.getRole();
		if (role.equals(Role.ROLE_ROOT)) {
			MessageResult result  = new MessageResult();
			result.setSuccess(true);
			return result;
		}
		if (role.equals(Role.ROLE_BOOK_ADMIN)) {
			if (operation.equals(Operation.BOOK_DELETE)
					|| operation.equals(Operation.BOOK_INSERT)
					|| operation.equals(Operation.BOOK_MODIFY)) {
				MessageResult result  = new MessageResult();
				result.setSuccess(true);
				return result;
			} else {
				MessageResult result  = new MessageResult();
				result.setSuccess(false);
				result.setMessage("操作无权限");
				return result;
			}
		}
		if (role.equals(Role.ROLE_ORDER_ADMIN)) {
			if (operation.equals(Operation.ORDER_DELETE)
					|| operation.equals(Operation.ORDER_PROCESS)) {
				MessageResult result  = new MessageResult();
				result.setSuccess(true);
				return result;
			} else {
				MessageResult result  = new MessageResult();
				result.setSuccess(false);
				result.setMessage("操作无权限");
				return result;
			}
		}
		if (role.equals(Role.ROLE_STAFF)){
			if (operation.equals(Operation.REPORT_TABLE)){
				MessageResult result  = new MessageResult();
				result.setSuccess(true);
				return result;
			} else {
				MessageResult result  = new MessageResult();
				result.setSuccess(false);
				result.setMessage("操作无权限");
				return result;
			}
		}
		if (role.equals(Role.ROLE_GUEST)){
			MessageResult result  = new MessageResult();
			result.setSuccess(true);
			return result;
		}
		MessageResult result  = new MessageResult();
		result.setSuccess(false);
		result.setMessage("操作无权限");
		return result;*/
	}
}
